package com.netty.client;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.timeout.IdleStateHandler;

import com.netty.coder.Server2ServerDecoder;
import com.netty.coder.Server2ServerEncoder;
import com.netty.handler.ClientChannelHandler;

public class ClientChannelInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pipeline = ch.pipeline();
		pipeline.addLast("heatBeat", new IdleStateHandler(12, 5, 0));
		pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
		pipeline.addLast("ssEncoder", new Server2ServerEncoder());
		pipeline.addLast("ssDecoder", new Server2ServerDecoder());
		pipeline.addLast("clientHandler", new ClientChannelHandler());
	}

}
